//
//  XLStatus.swift
//  WeiBo
//
//  Created by macbook on 16/10/19.
//  Copyright © 2016年 buWangChuXing. All rights reserved.
//

import UIKit

class XLStatus: NSObject {
    
    /// 微博创建时间
    var created_at: String?
    /// 微博ID
    var id: Int64 = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?
    
    //用户信息
    var user: XLUser?
    
     init(dict:[String:AnyObject]) {
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    //防止出错
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    
    //重写set v f k 完成user字典转模型
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            
            //判断是否有值,是否可以转成字典
            guard let res = value as? [String:AnyObject] else
            {
                return
            }
            
            //字典转模型
            let u = XLUser(dict: res)
            user = u
        }else
        {//如果重写了set value for key 我们还需要系统帮助我们通过kvc字典转模型，需要重写父类
            super.setValue(value, forKey: key)
        }
    }
    

}




















